<?
class module{

	var $id;
	var $nom;
	var $nomComplet;
	var $core;
	var $type;
	var $actif;
	var $description;
	var $auteur;
	var $version;
	var $parentModule;
	var $menuAdmin;
	var $dependance;

	function module($var){
		$this->id=$var->id;
		$this->nom=$var->nom;
		$this->nomComplet=$var->nomComplet;
		$this->core=$var->core;
		$this->type=$var->type;
		$this->actif=$var->actif;
		$this->description=$var->description;
		$this->auteur=$var->auteur;
		$this->version=$var->version;
		$this->parentModule=$var->parentModule;
		$this->menuAdmin=$var->menuAdmin;
		$this->dependance=$var->dependance;
	}

	function get_id(){ return stripslashes($this->id); }
	function set_id($value){ $this->id=$value; }
	function get_nom(){ return stripslashes($this->nom); }
	function set_nom($value){ $this->nom=$value; }
	function get_nomComplet(){ return stripslashes($this->nomComplet); }
	function set_nomComplet($value){ $this->nomComplet=$value; }
	function get_core(){ return stripslashes($this->core); }
	function set_core($value){ $this->core=$value; }
	function get_type(){ return stripslashes($this->type); }
	function set_type($value){ $this->type=$value; }
	function get_actif(){ return stripslashes($this->actif); }
	function set_actif($value){ $this->actif=$value; }
	function get_description(){ return stripslashes($this->description); }
	function set_description($value){ $this->description=$value; }
	function get_auteur(){ return stripslashes($this->auteur); }
	function set_auteur($value){ $this->auteur=$value; }
	function get_version(){ return stripslashes($this->version); }
	function set_version($value){ $this->version=$value; }
	function get_parentModule(){ return stripslashes($this->parentModule); }
	function set_parentModule($value){ $this->parentModule=$value; }
	function get_menuAdmin(){ return stripslashes($this->menuAdmin); }
	function set_menuAdmin($value){ $this->menuAdmin=$value; }
	function get_dependance(){ return stripslashes($this->dependance); }
	function set_dependance($value){ $this->dependance=$value; }

	function ajouter(){
		global $sql;
		$sqlr="insert into ".CFG_MYSQL_PREFIX."module(nom,nomComplet,core,type,actif,description,auteur,version,parentModule,menuAdmin,dependance) values('".addslashes($this->nom)."','".addslashes($this->nomComplet)."','".addslashes($this->core)."','".addslashes($this->type)."','".addslashes($this->actif)."','".addslashes($this->description)."','".addslashes($this->auteur)."','".addslashes($this->version)."','".addslashes($this->parentModule)."','".addslashes($this->menuAdmin)."','".addslashes($this->dependance)."')";
		$sql->query($sqlr,0);
	}

	function maj(){
		global $sql;
		$sql->query("update ".CFG_MYSQL_PREFIX."module set nom='".addslashes($this->nom)."',nomComplet='".addslashes($this->nomComplet)."',core='".addslashes($this->core)."',type='".addslashes($this->type)."',actif='".addslashes($this->actif)."',description='".addslashes($this->description)."',auteur='".addslashes($this->auteur)."',version='".addslashes($this->version)."',parentModule='".addslashes($this->parentModule)."',menuAdmin='".addslashes($this->menuAdmin)."',dependance='".addslashes($this->dependance)."' where id=".$this->id,0);
	}


	function check_dependance(){
		global $sql;
		$ret="";
		
		$tmp=explode(",",$this->dependance);
		foreach($tmp as $dep){
			if($dep!=""){
				$var=$sql->request_single("select actif from ".CFG_MYSQL_PREFIX."module where nom='".$dep."'");
				if($var===false) $ret.=" - ".$dep."<br />";
				elseif($var->actif=="0") $ret.=" - ".$dep."<br />";
			}
		}
		
		if($ret!=""){
			$ret="<span class='ui-icon ui-icon-alert tooltip' title='Erreur de dépendances :<br />".$ret."'></span>";
		}
		return $ret;
	}

	function getChildren(){
		global $sql;
		
		$tmp=array();
		$res=$sql->request("select nom from ".CFG_MYSQL_PREFIX."module where parentModule REGEXP '([^[:alnum:]]|^)".$this->nom."([^[:alnum:]]|$)'");
		foreach($res as $var){
			$tmp[]=$var->nom;
		}
		return $tmp;
	}
	
}

?>